home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Precision question
- Date: 13 Jan 1996 15:20:26 GMT
- Organization: Pipeline USA
- Message-ID: <4d8ijq$e9c@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe10.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 13, 1996 14:15:44 in article <Precision question>,
- 'dliska@ix.netcom.com (David Liska)' wrote:
-
-
- >I am starting to learn C++ and am a bit confused about how it handles
- >variable precision. I have the following lines of code:
- >
- > check1=num1/num2;
- > check2=int(check1);
- > if (check1 == check2)
- >
- >The purpose is to see if num1 is divisible by num2 with no remainder.
- >This works fine until I get into the 65k range. At this point, it
- >calculates every number from there on as "divisible".
-
- From your comments, I gather you're dealing with unsigned integers
- on a 16-bit machine. Your question really isn't about precicision
- but about the maximum (and minimum if signed) value that can
- be stored in a variable. On a 16-bit DOS machine, the maximum
- integer size is about 32K. Declaring the variable unsigned gives
- you one more bit so the max is 64K.
-
- If you need to work with integer values larger than 64K, use long
- or unsigned long variables. That'll give you 2 and 4 gigs respectively.
-
- >
- >I've tried setting check1 and check2 to long double, but it seems to
- >make no difference.
- >
-
- When you start using floating point variables (float, double,
- long double) you begin to run into problems with the equality
- test ("=="). After doing arithmetic, it is quite likely that two
- variables whose values we humans consider to be equal,
- will not be equal to the machine. With floats, you often have
- to resort to something like
-
- if (fabs(v1 - v2) < 0.00000001)
- cout << "They're EQ!!\n";
-
- --
-
- Pete
-